package cn.zn.controller.job;

import cn.zn.base.annotation.Log;
import cn.zn.base.bean.dto.ResultData;
import cn.zn.base.common.enums.BusinessType;
import cn.zn.base.common.utils.ResultUtil;
import cn.zn.job.service.SysJobLogService;
import cn.zn.job.vo.SysJobLogPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 调度日志操作处理
 *
 * @author zn-admin
 */
@RestController
@RequestMapping("/monitor/jobLog")
public class SysJobLogController {

    @Autowired
    private SysJobLogService jobLogService;

    /**
     * 查询定时任务调度日志列表
     */
    // @PreAuthorize("@ss.hasPermi('monitor:job:list')")
    @GetMapping("/list")
    public ResultData list(SysJobLogPageVo vo) {
        Object result = jobLogService.selectJobLogList(vo);
        return ResultUtil.success(result);
    }

    /**
     * 根据调度编号获取详细信息
     */
    // @PreAuthorize("@ss.hasPermi('monitor:job:info')")
    @GetMapping(value = "/{jobLogId}")
    public ResultData getInfo(@PathVariable String jobLogId) {
        return ResultUtil.success(jobLogService.getById(jobLogId));
    }

    @PreAuthorize("@ss.hasPermi('monitor:job:remove')")
    @Log(title = "调度日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{jobLogIds}")
    public ResultData remove(@PathVariable String[] jobLogIds) {
        jobLogService.deleteJobLogByIds(jobLogIds);
        return ResultUtil.success();
    }

    @PreAuthorize("@ss.hasPermi('monitor:job:remove')")
    @Log(title = "调度日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean/{jobId}")
    public ResultData clean(@PathVariable String jobId) {
        jobLogService.cleanJobLog(jobId);
        return ResultUtil.success();
    }

}
